﻿package com.pool.data
{
	import org.dm.utils.Iterator;
	import org.dm.utils.Map;
	
	public class UserDataMgr
	{
		private static var _instance:UserDataMgr = null;
		private static var _list:Map=new Map();
		
		private static var _me:UserData = new UserData();
		public static var meNetKey:String = "";
		public static var meAID:int;
		public static var meLoginKey:int;
		
		private var _userData:Map = new Map();
		
		public function UserDataMgr()
		{
			_userData = new Map();
		}
		
		public static function get Instance():UserDataMgr
		{
			if(_instance==null)
			{
				_instance = new UserDataMgr();
			}
			return _instance;
		}
		
		public static function get me():UserData
		{
			if(_instance==null)
			{
				_instance = new UserDataMgr();
			}
			return _me;
		}
		
		public function setMekey(pnetkey:String):void
		{
			me.netkey = pnetkey;
		}
		
		public function add(group:String,netkey:String,pars:Array):Boolean
		{
			if(_instance.getGroup(group)==null)
			{
				return false;
			}
			if(_instance.getGroup(group)._userData.find(netkey)!=null)
			{
				return false;
			}
			
			_instance.getGroup(group)._userData.insert(netkey,new UserData(netkey,pars));
			return true;
		}
		
		public function clearAll():void
		{
			_userData.clear();
		}
		
		public function Del(netkey:String):void
		{
			_userData.remove(netkey);
		}
		
		public function Find(netkey:String):UserData
		{
			var iter:Iterator = _userData.find(netkey);
			if(iter!=_userData.end)
			{
				return iter.data as UserData;
			}
			return null;
		}
		
		public function addGroup(sname:String,mgr:UserDataMgr):void
		{
			_list.insert(sname,mgr);
		}
		
		public function removeGroup(sname:String):void
		{
			return _list.remove(sname);
		}
		
		public function getGroup(sname:String):UserDataMgr
		{
			return _list.find(sname).data;
		}
		
		public function LoginOk(aid:uint,loginkey:uint):void
		{
			meAID= aid;
			meLoginKey = loginkey;
		}
		
		public function LoadDataOk(pnetkey:String,data:Array):void
		{
			meNetKey = pnetkey;
			me.netkey = pnetkey;
			me.SetAsArray(data);
			
			Common.RegCallBack("人员心跳", "Act", [me.netkey],null, true, 30000);
		}
	}
}